﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for clsSubBranchMasterDAL
/// </summary>
public class clsSubBranchMasterDAL
{
    InstantNaukriDataContextDataContext objInstantNaukriDataContextDataContext = new InstantNaukriDataContextDataContext();
    public clsSubBranchMasterDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public List<IN_TB_SUBBRANCH_MST> GetAllSubBranch()
    {
        try
        {
            List<IN_TB_SUBBRANCH_MST> objIN_TB_SUBBRANCH_MST = new List<IN_TB_SUBBRANCH_MST>();
            objIN_TB_SUBBRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      select obj).ToList();
            return objIN_TB_SUBBRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_SUBBRANCH_MST GetSubBranchById(int ID)
    {
        try
        {
            IN_TB_SUBBRANCH_MST objIN_TB_SUBBRANCH_MST = new IN_TB_SUBBRANCH_MST();
            objIN_TB_SUBBRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      where obj.ID == ID
                                      select obj).SingleOrDefault();
            return objIN_TB_SUBBRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_SUBBRANCH_MST GetSubBranchByUserId(int UserId)
    {
        try
        {
            IN_TB_SUBBRANCH_MST objIN_TB_SUBBRANCH_MST = new IN_TB_SUBBRANCH_MST();
            objIN_TB_SUBBRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      where obj.USER_ID == UserId
                                      select obj).SingleOrDefault();
            return objIN_TB_SUBBRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public int SaveSubBranchMst(IN_TB_SUBBRANCH_MST objIN_TB_SUBBRANCH_MST)
    {
        try
        {
            IN_TB_SUBBRANCH_MST objIN_TB_SUBBRANCH_MSTD = new IN_TB_SUBBRANCH_MST();
            objIN_TB_SUBBRANCH_MSTD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                       where obj.ID == objIN_TB_SUBBRANCH_MST.ID
                                       select obj).SingleOrDefault();
            if (objIN_TB_SUBBRANCH_MSTD != null)
            {
                objIN_TB_SUBBRANCH_MSTD.ID = objIN_TB_SUBBRANCH_MST.ID;
                objIN_TB_SUBBRANCH_MSTD.USER_ID = objIN_TB_SUBBRANCH_MST.USER_ID;
                objIN_TB_SUBBRANCH_MSTD.BRANCH_ID = objIN_TB_SUBBRANCH_MST.BRANCH_ID;
                objIN_TB_SUBBRANCH_MSTD.SUBBRANCH_DESCRIPTION = objIN_TB_SUBBRANCH_MST.SUBBRANCH_NAME;
                objIN_TB_SUBBRANCH_MSTD.SUBBRANCH_DESCRIPTION = objIN_TB_SUBBRANCH_MST.SUBBRANCH_DESCRIPTION;
                objIN_TB_SUBBRANCH_MSTD.EMAIL = objIN_TB_SUBBRANCH_MST.EMAIL;
                objIN_TB_SUBBRANCH_MSTD.MOBILE = objIN_TB_SUBBRANCH_MST.MOBILE;
                objIN_TB_SUBBRANCH_MSTD.PHONE = objIN_TB_SUBBRANCH_MST.PHONE;
                objIN_TB_SUBBRANCH_MSTD.STATUS = objIN_TB_SUBBRANCH_MST.STATUS;
                objIN_TB_SUBBRANCH_MSTD.CREATED_BY = objIN_TB_SUBBRANCH_MST.CREATED_BY;
                objIN_TB_SUBBRANCH_MSTD.CREATED_ON = objIN_TB_SUBBRANCH_MST.CREATED_ON;
                objIN_TB_SUBBRANCH_MSTD.MODIFIED_BY = objIN_TB_SUBBRANCH_MST.MODIFIED_BY;
                objIN_TB_SUBBRANCH_MSTD.MODIFIED_ON = objIN_TB_SUBBRANCH_MST.MODIFIED_ON;
                objIN_TB_SUBBRANCH_MSTD.DOWNLOAD_TILL = objIN_TB_SUBBRANCH_MST.DOWNLOAD_TILL;
                objIN_TB_SUBBRANCH_MSTD.LOGIN_TILL = objIN_TB_SUBBRANCH_MST.LOGIN_TILL;
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_SUBBRANCH_MSTD.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs.InsertOnSubmit(objIN_TB_SUBBRANCH_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                int NewID = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                             select obj.ID).Max();
                return NewID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    public void DeleteSubBranch(int SubBranchId)
    {
        try
        {
            IN_TB_SUBBRANCH_MST objIN_TB_SUBBRANCH_MST = new IN_TB_SUBBRANCH_MST();
            objIN_TB_SUBBRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      where obj.ID == SubBranchId
                                      select obj).SingleOrDefault();
            if (objIN_TB_SUBBRANCH_MST != null)
            {
                objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs.DeleteOnSubmit(objIN_TB_SUBBRANCH_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_USER GetUserBySubbranchId(int SubbranchId)
    {
        try
        {
            IN_TB_USER objIN_TB_SUBBRANCH_MST = new IN_TB_USER();
            objIN_TB_SUBBRANCH_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      join objuser in objInstantNaukriDataContextDataContext.IN_TB_USERs on obj.USER_ID equals objuser.ID
                                      where obj.ID == SubbranchId
                                      select objuser).SingleOrDefault();
            return objIN_TB_SUBBRANCH_MST;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<clsGetSubBranchInfo> GetAllSubBranchFullInfo()
    {
        try
        {
            List<clsGetSubBranchInfo> objclsGetSubBranchInfo = new List<clsGetSubBranchInfo>();
            objclsGetSubBranchInfo = new List<clsGetSubBranchInfo>();
            objclsGetSubBranchInfo = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      join objUser in objInstantNaukriDataContextDataContext.IN_TB_USERs on obj.USER_ID equals objUser.ID
                                      where objUser.ROLEID == 6
                                      select new clsGetSubBranchInfo

                                     {
                                         USERID = (int)objUser.ID,
                                         ID = (int)obj.ID,
                                         BRANCH_ID = (int)obj.BRANCH_ID,
                                         SUBBRANCH_NAME = obj.SUBBRANCH_NAME,
                                         SUBBRANCH_DESCRIPTION = obj.SUBBRANCH_DESCRIPTION,
                                         Download_Till = (DateTime)obj.DOWNLOAD_TILL,
                                         Login_Till = (DateTime)obj.LOGIN_TILL,
                                         EMAIL = objUser.EMAIL,
                                         MOBILE = objUser.MOBILE,
                                         NAME = objUser.NAME,
                                         PHONE = obj.PHONE,
                                         DOB = (DateTime)objUser.DOB,
                                         EMPLOYER_NAME = objUser.NAME,

                                     }
                                          ).ToList();




            return objclsGetSubBranchInfo;



        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<clsGetSubBranchInfo> GetAllSubBranchFullInfo(int BranchID)
    {
        try
        {
            List<clsGetSubBranchInfo> objclsGetSubBranchInfo = new List<clsGetSubBranchInfo>();
            objclsGetSubBranchInfo = new List<clsGetSubBranchInfo>();
            objclsGetSubBranchInfo = (from obj in objInstantNaukriDataContextDataContext.IN_TB_SUBBRANCH_MSTs
                                      join objUser in objInstantNaukriDataContextDataContext.IN_TB_USERs on obj.USER_ID equals objUser.ID
                                      where objUser.ROLEID == 6 && obj.BRANCH_ID==BranchID
                                      select new clsGetSubBranchInfo

                                      {
                                          USERID = (int)objUser.ID,
                                          ID = (int)obj.ID,
                                          BRANCH_ID = (int)obj.BRANCH_ID,
                                          SUBBRANCH_NAME = obj.SUBBRANCH_NAME,
                                          SUBBRANCH_DESCRIPTION = obj.SUBBRANCH_DESCRIPTION,
                                          Download_Till = (DateTime)obj.DOWNLOAD_TILL,
                                          Login_Till = (DateTime)obj.LOGIN_TILL,
                                          EMAIL = objUser.EMAIL,
                                          MOBILE = objUser.MOBILE,
                                          NAME = objUser.NAME,
                                          PHONE = obj.PHONE,
                                          DOB = (DateTime)objUser.DOB,
                                          EMPLOYER_NAME = objUser.NAME,

                                      }
                                          ).ToList();




            return objclsGetSubBranchInfo;



        }
        catch (Exception)
        {

            throw;
        }
    }
}
